package com.allianz.webapps.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.webapps.https.interfaces.appCover.AppOnParamChange.AppCoverOnParamChange;
import com.allianz.webapps.https.interfaces.appCover.pojo.AppEditCoverResponse;
import com.allianz.webapps.https.interfaces.util.HttpsUtil;
import com.allianz.webapps.orderspojo.Cover;
import com.fasterxml.jackson.databind.ObjectMapper;

@Controller
@RequestMapping(value = "main")
public class AppCoverOnParamChangeController {

	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private AppCoverOnParamChange appCoverOnParamChange;

	@RequestMapping("coveronparamchange")
	@ResponseBody
	public String appCoverOnParamChange(
			@RequestParam(value = "jsonParam") String jsonParam,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Cover cover = objectMapper.readValue(jsonParam, Cover.class);
		String body1 = HttpsUtil.httpsPost(appCoverOnParamChange
				.requestAppCoverOnParamChangeParam(cover));
		return body1;
/*		JSONObject json = new JSONObject(body1);
		String body = "";
		if (json.get("Body").equals(null)) {
			if (!"S".equals(json.getString("Statue")))
				throw new Exception(json.getString("ErrMsg"));
			else
				return null;
		}
		body = json.getString("Body");
		AppEditCoverResponse appEditCoverResponse = objectMapper.readValue(
				body, AppEditCoverResponse.class);
		return appEditCoverResponse;*/
	}
}
